package com.jia.jwt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jia.jwt.entity.User;
import com.jia.jwt.entity.vo.LoginVo;
import com.jia.jwt.mapper.UserMapper;
import com.jia.jwt.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dujiajia
 * @since 2021-01-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User getUserById(Long id) {
        User user = baseMapper.getUserById(id);
        return user;
    }

    @Override
    public User login(LoginVo user) {
        String username = user.getUsername();
        String password = user.getPassword();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);

        Integer count = baseMapper.selectCount(wrapper);
        if (count < 1){
            return null;
        }
        User selectOne = baseMapper.selectOne(wrapper);
        if (selectOne.getPassword().equals(password)){
            return selectOne;
        }else {
            return null;
        }
    }
}
